package grib2db;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.Vector;

public class EtimInfo {

	/**
	 * @param args
	 */
	public int layer;

	public String[] getGrib2Item() {
		Properties pro = new Properties();
		try {
			pro.load(new FileInputStream("config/config.property"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		String itemlist = pro.getProperty("itemlist");
		String[] item = itemlist.split(" ");
		/*
		 * for(int i =0;i<item.length;i++) { System.out.println(item[i]); String
		 * iteminfo = pro.getProperty(item[i]); String [] iteminfoArry =
		 * iteminfo.split(" "); for(int j =0;j<iteminfoArry.length;j++) {
		 * System.out.println(iteminfoArry[j]); } }//
		 */
		return item;
	}

	public int getItemLayer(String item) {
		Properties pro = new Properties();
		try {
			pro.load(new FileInputStream("config/config.property"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		String iteminfo = pro.getProperty(item);
		String[] iteminfoArry = iteminfo.split(" ");
		int layer = Integer.parseInt(iteminfoArry[0]);
		return layer;
	}

	public int[] getItemGrib2Info(String item) {
		Properties pro = new Properties();
		try {
			pro.load(new FileInputStream("config/config.property"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		String grib2 = pro.getProperty(item);
		String[] grib2Arry = grib2.split(" ");
		Vector<Integer> gribinfo = new Vector<Integer>();
		for (int i = 1; i < grib2Arry.length; i++) {
			int temp = Integer.parseInt(grib2Arry[i]);
			// System.out.println(temp);
			gribinfo.add(temp);
		}
		int[] grib2info_int = new int[gribinfo.size()];
		for (int i = 0; i < gribinfo.size(); i++) {
			grib2info_int[i] = gribinfo.get(i);
			// System.out.println(gribinfo.indexOf(i));
		}
		return grib2info_int;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		EtimInfo ei = new EtimInfo();
		String[] item = ei.getGrib2Item();
		for (int i = 0; i < item.length; i++) {
			System.out.println(item[i]);
			System.out.println(ei.getItemLayer(item[i]));
			int[] a = ei.getItemGrib2Info(item[i]);
			for (int j = 0; j < a.length; j++) {
				System.out.println(a[j]);
			}
		}
	}

}
